package com.zjy.business.system.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zjy.business.system.domain.entity.SysUserRole;
import com.zjy.business.system.mapper.SysUserRoleMapper;
import com.zjy.config.RedisServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @author yxb
 * create_time: 2024-10-22 14:45
 * description: 
 */
@Service
public class SysUserRoleDao extends RedisServiceImpl<SysUserRoleMapper, SysUserRole> {
    public void removeByUserId(Long userId) {
        LambdaQueryWrapper<SysUserRole> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysUserRole::getUserId, userId);
        this.remove(wrapper);
    }

    /**
     * 检查角色是否被用户绑定
     * @param roleId 角色id
     * @return 绑定数量
     */
    public long checkRoleIsBindUser(Long roleId) {
        return this.lambdaQuery()
                .eq(SysUserRole::getRoleId, roleId)
                .count();
    }
}
